import fetch from '../../utils/request';

export async function getAllBriefConfigsAxios(userName){//获取当前用户保存的的所有除webapi以外的简短连接配置
  const params = {
    userName,
  }
  return fetch({
    url: '/api/connectionConfig/getAllBriefConfigs',
    method: 'get',
    params
  });
}

export async function getAllBriefWebApiConfigsAxios(userName){//获取当前用户保存的的所有webapi的简短连接配置
  const params = {
    userName,
  }
  return fetch({
    url: '/api/connectionConfig/getAllBriefWebApiConfigs',
    method: 'get',
    params
  });
}

export async function getAllTablesAxios(dataType,params){//获取指定数据库下所有表
  let dbType = dataType.toLowerCase();
  return fetch({
    url: `/api/${dbType}/getAllTables`,
    method: 'get',
    params
  });
}

export async function getAllColumnFamiliesAxios(id,database){//获取hbase指定表下的列族
  const params = {
    id,database
  }
  return fetch({
    url: '/api/hbase/getAllColumnFamilies',
    method: 'get',
    params
  });
}

export async function getAllColumnsAxios(dataType,params){//获取指定表下所有列名
  let dbType = dataType.toLowerCase();
  return fetch({
    url: `/api/${dbType}/getAllColumns`,
    method: 'get',
    params
  });
}

//web接口相关配置
export async function getAllFieldsAxios(databaseId){//获取api接口的所有字段
  const params = {
    databaseId
  }
  return fetch({
    url: '/api/webapi/getAllFields',
    method: 'get',
    params
  });
}

export async function addWebApiEleAxios(taskId,databaseSymbol,databaseId,fieldNames){//添加webapi输入组件
  const params = {
    taskId,databaseSymbol,databaseId,fieldNames//databaseSymbol取值只有0
  }
  return fetch({
    url: '/api/webapi/addEle',
    method: 'patch',
    params
  });
}

//获取任务的输入输出组件的属性值
export async function getAllInputFieldAxios(taskId){//获取此任务源数据库以及字段转换组件的字段配置
  const params = {
    taskId
  }
  return fetch({
    url: '/api/getOTF/getAllInputField',
    method: 'get',
    params
  });
}

export async function getOriginFieldAxios(taskId){//获取此任务源数据库的字段配置
  const params = {
    taskId
  }
  return fetch({
    url: '/api/getOTF/getOriginField',
    method: 'get',
    params
  });
}

export async function getTargetFieldAxios(taskId){//获取此任务目标数据库的字段配置
  const params = {
    taskId
  }
  return fetch({
    url: '/api/getOTF/getTargetField',
    method: 'get',
    params
  });
}

//添加输入或输出组件
export async function addEleAxios(dataType,params){
  let dbType = dataType.toLowerCase();
  return fetch({
    url: `/api/${dbType}/addEle`,
    method: 'get',
    params
  });
}

//字段计算组件接口
export async function addCalculatorAxios(taskId,data){//添加字段计算组件
  const params = {
    taskId,data
  }
  return fetch({
    url: '/api/calculator/add',
    method: 'post',
    params
  });
}

export async function deleteCalculatorAxios(id){//删除字段计算组件
  const params = {
    id//任务id
  }
  return fetch({
    url: '/api/calculator/delete',
    method: 'post',
    params
  });
}

export async function getCalcTypeAxios(){//获取字段计算组件中的计算类型的属性
  return fetch({
    url: '/api/calculator/getCalcTypeProperty',
    method: 'get',
  });
}

// export async function getCalcEleAxios(){//获取字段计算组件的属性
//   return fetch({
//     url: '/api/calculator/getCalculatorEleProperty',
//     method: 'get',
//     params
//   });
// }

export async function getCalcValueAxios(){//获取字段计算组件中的值类型的属性
  return fetch({
    url: '/api/calculator/getValueTypeProperty',
    method: 'get',
  });
}

//字段替换组件接口类
export async function addReplacementAxios(taskId,data){//添加字段替换组件
  const params = {
    taskId,data
  }
  return fetch({
    url: '/api/replaceString/add',
    method: 'post',
    params
  });
}

export async function deleteReplacementAxios(id){//删除字段替换组件
  const params = {
    id
  }
  return fetch({
    url: '/api/replaceString/deleteReplaceStringEle',
    method: 'post',
    params
  });
}

//字段过滤组件接口类
export async function addFilterAxios(taskId,data){//添加字段过滤组件
  const params = {
    taskId,data
  }
  return fetch({
    url: '/api/filterRows/add',
    method: 'post',
    params
  });
}

//字段合并组件接口
export async function addMergeAxios(params){//添加字段合并信息
  // const params = {
  //   taskId,joinTypes,keyField1,keyField2
  // }
  return fetch({
    url: '/api/mergeJoin/add',
    method: 'post',
    params
  });
}

export async function addMergeDatabaseAxios(params){//添加数据配置id到字段合并组件中
  // const params = {
  //   taskId,databaseId
  // }
  return fetch({
    url: '/api/mergeJoin/addDatabase',
    method: 'post',
    params
  });
}

//任务设置
export async function addOriConfigAxios(taskId,databaseId){//添加任务的源数据库配置接口
  const params = {
    taskId,databaseId
  }
  return fetch({
    url: '/api/task/addOriConfig',
    method: 'post',
    params
  });
}

export async function addTarConfigAxios(taskId,databaseId){//添加任务的目标数据库配置接口
  const params = {
    taskId,databaseId
  }
  return fetch({
    url: '/api/task/addTarConfig',
    method: 'post',
    params
  });
}

export async function addTimingEleAxios(repeat,taskId,timingType,jsonStr){//添加定时任务时间配置
  const params = {
    repeat,taskId,timingType,jsonStr
  }
  return fetch({
    url: '/api/task/addTimingEle',
    method: 'post',
    params
  });
}

export async function buildTaskAxios(taskType,taskName,userName){//建立task
  const params = {
    taskType,taskName,userName
  }
  return fetch({
    url: '/api/task/build',
    method: 'get',
    params
  });
}

export async function commitTaskAxios(taskId){//提交任务
  const params = {
    taskId
  }
  return fetch({
    url: '/api/task/commitTask',
    method: 'post',
    params
  });
}

export async function pauseTaskAxios(taskId){//暂停/重启任务
  const params = {
    taskId
  }
  return fetch({
    url: '/api/task/pause',
    method: 'post',
    params
  });
}

export async function runTaskAxios(taskId){//执行任务
  const params = {
    taskId
  }
  return fetch({
    url: '/api/task/run',
    method: 'post',
    params
  });
}

export async function stopTaskAxios(taskId){//终止任务
  const params = {
    taskId
  }
  return fetch({
    url: '/api/task/stop',
    method: 'post',
    params
  });
}

//任务监控模块
export async function deleteTaskAxios(taskId){//删除任务
  const params = {
    taskId
  }
  return fetch({
    url: '/api/monitor/deleteTaskById',
    method: 'post',
    params
  });
}

export async function getAllTaskAxios(userName){//获取所有未完成执行的任务
  const params = {
    userName
  }
  return fetch({
    // url: '/api/monitor/getAllTask',
    url: '/api/monitor/getAllNoStartTaskByUser',
    method: 'get',
    params
  });
}

export async function getTaskInfoAxios(taskId){//获取任务详情
  const params = {
    taskId
  }
  return fetch({
    url: '/api/monitor/getTaskInfos',
    method: 'get',
    params
  });
}

//历史任务接口
export async function getHistoryTaskLogAxios(taskId){
  const params = {
    taskId
  }
  return fetch({
    url: '/api/history/getTaskLogInfo',
    method: 'get',
    params
  });
}

export async function getHistoryTaskAxios(userName){
  const params = {
    userName
  }
  return fetch({
    // url: '/api/history/getTask',
    url: '/api/history/getHistoryTask',
    method: 'get',
    params
  });
}

export async function cumulativeTransTask(params){ // 获取历史任务的详细执行日志
  return fetch({
    url: '/api/history/cumulativeTransTask',
    method: 'get',
    params
  })
}

export async function getTransLog(params){ // 获取某个用户的详细执行日志
  return fetch({
    url: '/api/history/getTransLog',
    method: 'get',
    params
  })
}